﻿using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.SafeManage;
using LJX.SmartPark.Service.SafeManage;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace LJX.SmartPark.WebApi.Controllers.SafeManage
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "SafeManage")]
    public class SafeManageController : ControllerBase
    {
        private readonly IHouseInfoService _houseInfoService;

        private readonly IPatrolCollocateService _patrolCollocateService;

        private readonly IPatrolpathService _patrolpathService;

        private readonly IPatroldetailService _patroldetailService;

        public SafeManageController(IHouseInfoService houseInfoService, IPatrolCollocateService patrolCollocateService, IPatrolpathService patrolpathService, IPatroldetailService patroldetailService)
        {
            _houseInfoService = houseInfoService;
            _patrolCollocateService = patrolCollocateService;
            _patrolpathService = patrolpathService;
            _patroldetailService = patroldetailService;
        }

        #region 巡更点配置

        [HttpPost]
        public object GrtTreeHouseInfo()
        {
            return _houseInfoService.GrtTreeHouseInfo();
        }

        [HttpPost]
        public object GetHouseInfoSelect()
        {
            return _houseInfoService.GetHouseInfoSelect();
        }

        /// <summary>
        /// 添加巡更点
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<bool>> PostAddPatrolCollocate(PatrolCollocate input)
        {
            var result = _patrolCollocateService.PostAddPatrolCollocate(input);
            return result;
        }

        [HttpPost]
        public string GetPatrolCollocateNum()
        {
            Random rd = new Random();
            var Num = "XG" + rd.Next(100000, 1000000).ToString();
            return Num;
        }

        /// <summary>
        /// 删除巡更点
        /// </summary>
        /// <param name="input"></param>
        [HttpDelete]
        public Task<Response<bool>> DeleteById(PatrolCollocate input)
        {
            var result = _patrolCollocateService.DeleteByIdAsync(input);
            return result;
        }

        /// <summary>
        /// 修改巡更点
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<Response<bool>> PutUpdatePatrolCollocate(PatrolCollocate input)
        {
            var result = _patrolCollocateService.PutUpdatePatrolCollocate(input);

            return result;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Response<List<PatrolCollocate>> GetPatrolCollocateAsync(PatrolCollocateForm form)
        {
            var result = _patrolCollocateService.GetPatrolCollocateAsync(form);
            return result.Result;
        }

        #endregion

        #region 巡更路线
        [HttpPost]
        public Task<Response<List<PatrolCollocate>>> GetListPatrolCollocateAsync()
        {
            var result = _patrolCollocateService.GetListPatrolCollocateAsync();
            return result;
        }


        /// <summary>
        /// 添加巡更路线
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<Response<bool>> PostAddPatrolpath(Patrolpath input)
        {
            var result = _patrolpathService.PostAddPatrolpath(input);
            return result;
        }

        /// <summary>
        /// 删除巡更路线
        /// </summary>
        /// <param name="input"></param>
        [HttpDelete]
        public Task<Response<bool>> DeletePatrolpathById(Patrolpath input)
        {
            var result = _patrolpathService.DeleteByIdAsync(input);
            return result;
        }

        /// <summary>
        /// 修改巡更路线
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public Task<Response<bool>> PutUpdatePatrolpath(Patrolpath input)
        {
            var result = _patrolpathService.PutUpdatePatrolpath(input);

            return result;

        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object GetPatrolpath(PatrolpathForm form)
        {
            var result = _patrolpathService.GetPatrolpath(form);
            return result;
        }

        [HttpPost]
        public bool PostAddPatroldetail(patroldetail input)
        {
            var result = _patroldetailService.PostAddPatroldetail(input);
            return result;
        }

        [HttpPost]
        public List<Patroldetail> GetIdPatroldetail(Patrolpath input)
        {
            var result = _patroldetailService.GetIdPatroldetail(input);
            return result;
        }

        #endregion
    }
}
